package com.hngates.architecture.controller;

import java.util.List;

import com.hngates.architecture.domain.vo.ArcBuilderCompanyVO;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import com.hngates.common.annotation.Log;
import com.hngates.common.enums.BusinessType;
import com.hngates.architecture.domain.ArcBuilderCompany;
import com.hngates.architecture.service.IArcBuilderCompanyService;
import com.hngates.common.core.controller.BaseController;
import com.hngates.common.core.domain.AjaxResult;
import com.hngates.common.utils.poi.ExcelUtil;
import com.hngates.common.core.page.TableDataInfo;

/**
 * 建设单位Controller
 * 
 * @author jwhe
 * @date 2022-07-04
 */
@Controller
@RequestMapping("/architecture/builderCompany")
public class ArcBuilderCompanyController extends BaseController
{
    private String prefix = "architecture/builderCompany";

    @Autowired
    private IArcBuilderCompanyService arcBuilderCompanyService;

    @RequiresPermissions("architecture:builderCompany:view")
    @GetMapping()
    public String builderCompany()
    {
        return prefix + "/builderCompany";
    }

    /**
     * 查询建设单位列表
     */
    @RequiresPermissions("architecture:builderCompany:list")
    @PostMapping("/list")
    @ResponseBody
    public TableDataInfo list(ArcBuilderCompany arcBuilderCompany)
    {
        startPage();
        List<ArcBuilderCompanyVO> list = arcBuilderCompanyService.selectArcBuilderCompanyVOList(arcBuilderCompany);
        return getDataTable(list);
    }

    /**
     * 导出建设单位列表
     */
    @RequiresPermissions("architecture:builderCompany:export")
    @Log(title = "建设单位", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    @ResponseBody
    public AjaxResult export(ArcBuilderCompany arcBuilderCompany)
    {
        List<ArcBuilderCompany> list = arcBuilderCompanyService.selectArcBuilderCompanyList(arcBuilderCompany);
        ExcelUtil<ArcBuilderCompany> util = new ExcelUtil<ArcBuilderCompany>(ArcBuilderCompany.class);
        return util.exportExcel(list, "建设单位数据");
    }

    /**
     * 新增建设单位
     */
    @GetMapping("/add")
    public String add()
    {
        return prefix + "/add";
    }

    /**
     * 新增保存建设单位
     */
    @RequiresPermissions("architecture:builderCompany:add")
    @Log(title = "建设单位", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    @ResponseBody
    public AjaxResult addSave(ArcBuilderCompany arcBuilderCompany)
    {
        return toAjax(arcBuilderCompanyService.insertArcBuilderCompany(arcBuilderCompany));
    }

    /**
     * 修改建设单位
     */
    @RequiresPermissions("architecture:builderCompany:edit")
    @GetMapping("/edit/{id}")
    public String edit(@PathVariable("id") Long id, ModelMap mmap)
    {
        ArcBuilderCompany arcBuilderCompany = arcBuilderCompanyService.selectArcBuilderCompanyById(id);
        mmap.put("arcBuilderCompany", arcBuilderCompany);
        return prefix + "/edit";
    }

    /**
     * 修改保存建设单位
     */
    @RequiresPermissions("architecture:builderCompany:edit")
    @Log(title = "建设单位", businessType = BusinessType.UPDATE)
    @PostMapping("/edit")
    @ResponseBody
    public AjaxResult editSave(ArcBuilderCompany arcBuilderCompany)
    {
        return toAjax(arcBuilderCompanyService.updateArcBuilderCompany(arcBuilderCompany));
    }

    /**
     * 删除建设单位
     */
    @RequiresPermissions("architecture:builderCompany:remove")
    @Log(title = "建设单位", businessType = BusinessType.DELETE)
    @PostMapping( "/remove")
    @ResponseBody
    public AjaxResult remove(String ids)
    {
        return toAjax(arcBuilderCompanyService.deleteArcBuilderCompanyByIds(ids));
    }
}
